package com.shenglue.ssi.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.shenglue.ssi.domain.DicCat;
import com.shenglue.ssi.service.DicCatService;

public class DicCatAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	private DicCat diccat;     // 对应的 Bean
	private int diccatId;    // 删除/修改 的 记录之Id
	private DicCatService diccatService;  // 依赖的 Service

	public DicCatService getDicCatService() {
		return diccatService;
	}

	public void setDicCatService(DicCatService diccatService) {
		this.diccatService = diccatService;
	}

	public DicCat getDicCat() {
		return diccat;
	}

	public void setDicCat(DicCat diccat) {
		this.diccat = diccat;
	}

	public int getDicCatId() {
		return diccatId;
	}

	public void setDicCatId(int diccatId) {
		this.diccatId = diccatId;
	}

	public DicCatAction() {
	}


	/**
	 * 查询所有tb_DicCat 信息方法
	 */
	public String queryAll() throws Exception {
		List<DicCat> list = diccatService.selectAllDicCat();
		if(list!=null){
			HttpServletRequest request = ServletActionContext.getRequest();
			request.setAttribute( "diccatList", list );
		}else{
			// 不能认为是错误，因为一开始是没有数据的  return INPUT;
		}
		return SUCCESS;
	}

	/**
	 * 增加tb_DicCat记录方法
	 */
	public String addNew() throws Exception {
		boolean flag = diccatService.saveDicCat( diccat );
		if(flag==true){
			return SUCCESS;
		}else{
			return ERROR;
		}
	}

	/**
	 * 删除tb_DicCat记录方法
	 */
	public String delete() throws Exception {

		// 获取request对象
		boolean flag = diccatService.deleteDicCat( diccatId );
		if( flag == true ) {
			return SUCCESS;
		}else{
			return ERROR;
		}
	}

	/**
	 * 修改tb_DicCat记录方法
	 */
	public String update() throws Exception {

		boolean flag = diccatService.updateDicCat( diccat );
		if( flag == true ) {
			return SUCCESS;
		}else{
			return ERROR;
		}
	}
}
